package Sliding_Window;

import jdk.jfr.ContentType;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/17 16:02
 */
public class L1208 {
    public static void main(String[] args) {
        L1208 l1208 = new L1208();
        l1208.equalSubstring("abcd","bcdf",3);
    }
    public int equalSubstring(String s, String t, int maxCost) {
        int ans = 0;
        int curCost = 0;
        int count = 0;
        int leftIndex = 0;
        for (int rightIndex = 0; rightIndex < s.length(); ) {
            if(curCost + Math.abs(s.charAt(rightIndex) - t.charAt(rightIndex)) <= maxCost){
                curCost += Math.abs(s.charAt(rightIndex) - t.charAt(rightIndex));
                rightIndex++;
                count++;
            }else {
                curCost -= Math.abs(s.charAt(leftIndex) - t.charAt(leftIndex));
                leftIndex++;
                count--;
            }
            ans = Math.max(ans,count);
        }
        return ans;
    }
}